package com.share.constant;

public enum StatusCode {
    SUCCESS(200, "操作成功"),
    TOKEN_ERROR(401, "令牌无效"),
    NOT_FOUND(404, "未找到资源"),
    INTERNAL_ERROR(500, "内部服务器错误"),
    USERNAME_EXIST(504, "用户名已存在"),
    USERNAME_NOT_EXIST(505, "用户不存在"),
    PASSWORD_ERROR(506, "密码错误"),
    REGISTER_FAIL(507, "注册失败"),
    CAPTCHA_ERROR(508, "验证码错误"),
    PHONE_FORMAT_ERROR(509, "手机号格式错误"),
    CAPTCHA_OVER_TIME(510, "验证码过期"),
    PHONE_EXIST(511, "手机号已经注册"),
    LOGOUT_FAIL(512, "注销失败"),
    LOGOUT_SUCCESS(513, "注销成功"),
    USER_INFO_ERROR(514, "用户信息错误"),
    FILENAME_IS_BLANK(515, "文件名不能为空"),
    FILE_NOT_EXIST(516, "文件不存在"),
    FILE_EXIST(517, "文件已存在"),
    FILE_PATH_ERROR(518, "文件路径错误"),
    FILE_SIZE_ERROR(519, "文件大小错误"),
    FILE_TYPE_ERROR(520, "文件类型错误"),
    FILE_UPLOAD_FAIL(521, "文件上传失败"),
    FILE_DOWNLOAD_FAIL(522, "文件下载失败"),
    FILE_DELETE_FAIL(523, "文件删除失败"),
    LOGIN_OUT_MESSAGE(550,"用户异地登录,请重新登录"),
    USER_NOT_LOGIN(551,"用户未登录"),
    FILE_COPY_FAIL(552, "文件复制失败"),
    FILE_RENAME_FAIL(553, "文件重命名失败"),
    FILE_CREATE_FAIL(554, "文件创建失败"),
    USER_REGISTER_FAIL(590,"新增用户失败" ),
    USER_DELETE_FAIL(591, "用户状态切换失败"),
    USER_UPDATE_FAIL(592,"用户信息修改失败" );



    private final int code;
    private final String message;

    StatusCode(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    @Override
    public String toString() {
        return "StatusCode{" +
                "code=" + code +
                ", message='" + message + '\'' +
                '}';
    }

    // 可选：根据code查找对应的StatusCode
    public static StatusCode fromCode(int code) {
        for (StatusCode statusCode : values()) {
            if (statusCode.getCode() == code) {
                return statusCode;
            }
        }
        throw new IllegalArgumentException("No matching status found for code: " + code);
    }
}
